package com.itheima.service;

import com.itheima.common.R;
import com.itheima.mapper.SetmealMapper;
import com.itheima.mapper1.DishClientMapper;
import com.itheima.mapper1.DishFlavorClientMapper;
import com.itheima.mapper1.SetmealClientMapper;
import com.itheima.mapper1.SetmealDishClientMapper;
import com.itheima.pojo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wuyiqiang
 * @2022/6/18 16:59
 */
@Service
public class SetmealClientService {

    @Autowired
    private SetmealClientMapper setmealClientMapper;
    @Autowired
    private SetmealDishClientMapper setmealDishClientMapper;
    @Autowired
    private DishClientMapper dishClientMapper;

    /**
     * 菜品信息详情
     *
     * @param id
     * @return
     */
    public R<List<Dish>> findDish(String id) {
        //根据id查找到对应的套餐
        Setmeal select = setmealClientMapper.select(id);
        System.out.println(id + "================debug");
        //属性拷贝
        SetmealDto setmealDto = new SetmealDto();
        BeanUtils.copyProperties(select, setmealDto);
        //查询该套餐的菜品
        List<SetmealDish> setmealDishes = setmealDishClientMapper.selectByDishId(setmealDto.getId());
        //根据菜品id查询菜品信息
        List<Dish> dishList=new ArrayList<>();
        for (SetmealDish setmealDish : setmealDishes) {
            Dish byId = dishClientMapper.findById(setmealDish.getDishId());
            dishList.add(byId);
        }

        return R.success(dishList);
    }

    /**
     * 套餐列表
     *
     * @param categoryId
     * @param status
     * @return
     */
    public R<List<Setmeal>> selectDish(String categoryId, Integer status) {
        //查询套餐基本信息
        List<Setmeal> setmeal = setmealClientMapper.selectById(categoryId, status);

        return R.success(setmeal);

    }
}
